﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using Microsoft.Drawing;
using TouchRC.Themes;
using TouchRC.Custom_Controls.Events;

namespace TouchRC.Custom_Controls
{
    public class AdjustableLabel : FluidLabel
    {
        private int m_BaseHeight = 0;

        protected override void InitControl()
        {
            base.InitControl();
            Font = Theme.CurrentTheme.StandardFont;
            Visible = true;
        }

        protected override void OnTextChanged()
        {
            base.OnTextChanged();

            ReadjustHeight();
        }

        public event EventHandler<HeightChangedEventArgs> HeightChanged;

        public int BaseHeight
        {
            get { return m_BaseHeight; }
            set { m_BaseHeight = value; }
        }

        public void ReadjustHeight()
        {
            Size heightAdjustment = Size.Empty;

            using (Graphics graphics = CreateGraphics())
            {
                heightAdjustment = graphics.MeasureStringEx(Text, Font,
                    Width);
            }

            Height = m_BaseHeight + heightAdjustment.Height;

            if (HeightChanged != null)
            {
                HeightChangedEventArgs heightEvent = new HeightChangedEventArgs();
                heightEvent.NewHeight = Height;
                HeightChanged(this, heightEvent);
            }
        }
    }
}
